package com.healtyprj;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import com.amazonaws.auth.ClasspathPropertiesFileCredentialsProvider;
import com.amazonaws.services.dynamodb.AmazonDynamoDB;
import com.amazonaws.services.dynamodb.AmazonDynamoDBClient;
import com.amazonaws.services.dynamodb.datamodeling.DynamoDBMapper;
import com.amazonaws.services.dynamodb.datamodeling.DynamoDBQueryExpression;
import com.amazonaws.services.dynamodb.datamodeling.DynamoDBScanExpression;
import com.amazonaws.services.dynamodb.model.AttributeValue;
import com.amazonaws.services.dynamodb.model.ComparisonOperator;
import com.amazonaws.services.dynamodb.model.Condition;
import com.amazonaws.util.DateUtils;

public class SaveUser {

	public SaveUser() {
		super();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		AmazonDynamoDB dynamoDB = new AmazonDynamoDBClient(new ClasspathPropertiesFileCredentialsProvider());
		dynamoDB.setEndpoint("dynamodb.ap-northeast-1.amazonaws.com");

		DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(dynamoDB);
		
		/*
		User user = new User();
		user.setName("A");
		user.setPassword("p");
		dynamoDBMapper.save(user);
		user = new User();
		user.setName("O");
		user.setPassword("p");
		dynamoDBMapper.save(user);
		user = new User();
		user.setName("S");
		user.setPassword("p");
		dynamoDBMapper.save(user);
		user = new User();
		user.setName("F");
		user.setPassword("p");
		dynamoDBMapper.save(user);
		user = new User();
		user.setName("N");
		user.setPassword("p");
		dynamoDBMapper.save(user);
		 */
		/*
		Weight weight = new Weight();
		weight.setName("薫");
		weight.setDate("2013/01/02");
		weight.setWeight("65.3");
		weight.setMemo("memo2");
		dynamoDBMapper.save(weight);
		*/
		/*
		Goal goal = new Goal();
		goal.setName("薫");
		goal.setStartDate("2013/02/01");
		goal.setFinishDate("2013/02/07");
		goal.setWeight("60.5");
		dynamoDBMapper.save(goal);
		*/
		
		SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");
		Condition rangeKeyCondition = new Condition()
		.withComparisonOperator(ComparisonOperator.GT.toString())
		.withAttributeValueList(new AttributeValue().withS(format.format(new Date())));

		//ハッシュキーを設定
		DynamoDBQueryExpression queryExpression = new DynamoDBQueryExpression(
				new AttributeValue().withS("薫"));

		//レンジキーの検索条件を設定
		queryExpression.setRangeKeyCondition(rangeKeyCondition);

		//検索結果を取得
		// "lazy-loaded" コレクションで返ってきます。
		List<Goal> latestReplies = dynamoDBMapper.query(Goal.class, queryExpression);
		for (Goal goal2 : latestReplies) {
			System.out.format("Id=%s, Message=%s, PostedBy=%s %n, ReplyDateTime=%s %n",
					goal2.getName(), goal2.getFinishDate(), goal2.getWeight(), goal2.getStartDate());
		}
		/*
		for (Weight weight2 : latestReplies) {
			System.out.format("Id=%s, Message=%s, PostedBy=%s %n, ReplyDateTime=%s %n",
					weight2.getName(), weight2.getDate(), weight2.getWeight(), weight2.getMemo() );
		}
		*/
	}

}
